<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    {include file="../tpl/header.html" /}
</head>
<body>
{include file="../tpl/menu.html" /}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form" method="post" action="{:url('admin/admin/roleEdit')}">
            <div class="layui-form-item">
                <label class="layui-form-label"><span class="x-red">*</span>角色名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" value="{$data.name}" name="name" required="" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>角色的名称
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label for="introduce" class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="introduce" name="introduce" class="layui-textarea">{$data.introduce}</textarea>
                </div>
            </div>
            <input type="hidden" name="role_id" value="{$data.role_id}">
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="add" lay-submit="">更新</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form', 'layer'],
    function() {
        $ = layui.jquery;
        var form = layui.form, layer = layui.layer;
        //监听提交
        form.on('submit(add)', function(data) {
            $.ajax({
                type:'post',
                data:data.field,
                dataType:'json',
                url:"{:url('admin/admin/roleEdit')}",
                success:function (e) {
                    if(e.code === 1){
                        layer.msg(e.msg, {icon: 6,time: layer_msg_success_time},
                            function() {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                parent.location.reload();
                            });
                    }else{
                        layer.msg(e.msg, {icon: 5,time: layer_msg_error_time});
                    }
                }
            });
            //发异步，把数据提交给php
            return false;
        });
    });
</script>
</body>
</html>